<!--
 * @Descripttion: 
 * @Version: 
 * @Author: gaohj
 * @Date: 2022-10-27 10:46:04
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-27 11:35:42
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * @function: 
         * @description: 
         * @param {*} num1
         * @param {*} num2
         * @return {*}
         */
        function tosum(num1, num2) {
            return num1 + num2;
        }


        var test = [70, 88, 91, 70, 107, 234, 91, 177, 282, 197];

        var new_array = [];
        // for(var i=0;i<test.length;i++){
        //     if(new_array.indexOf(i) == -1){
        //         new_array.push(test[i]);
        //     }
        // }


        for (var index in test) {
            if (new_array.indexOf(test[index]) == -1) {
                new_array.push(test[index]);
            }
        }

        document.write(new_array.sort(function (a, b) {
            return b - a
        }));


        /**
         * @function: 
         * @description: 
         * @param {Array} arr
         * @return {Array}
         */        
        function unique_arr(arr){
            var new_array = []; // 创建一个新的变量存放空数组  
            for (var index in arr) {
                if (new_array.indexOf(arr[index]) == -1) {
                    new_array.push(arr[index]);
                }
            }

            
            return new_array.sort(function (a, b) {return b - a});
        }

        /**
         * @function: 
         * @description: 
         * @param {*} arr
         * @return {*}
         * @author: gaohj
         * @example: 
         */             
        function find_min_array(arr){
            var min = arr[0];
            for(var i=1;i<arr.length;i++){
                if(arr[i]<min){
                    min = arr[i]
                }
            }

            return min;
        }




        num_arr = [34,6,546,5,100,16,77,56,88,10];

        var max= num_arr[0];
        var res = 0;
        for(var i=1;i<num_arr.length;i++){
            if(num_arr[i]>max){
                max = num_arr[i];
                res = i;
            }
        }


        //  for 循环结束以后 i的结果是10 
        // 所以在for 循环外边打印i 永远是10 

        // console.log(max,res);


        num_list = [34,6,546,5,100,546,546,16,77];
        // [5,6,16,34,77,100,546,546,546];
        // 9-546出现的次数-1 这就是100的下标  // 100就是第二大 

        // 求第二大值 

        // 求每个数字出现的次数 
        // {}

        // {5:1,6:1,16:1,34:1,77:1,100:1,546:3}

        //对象["546"] = 3 

        mymap = {};

        for(var index in num_list){
            var key = num_list[index];
            if(mymap[key]){
                mymap[key] +=1;
            }else{
                mymap[key] = 1;
            }
        }
        console.log(mymap);
        var max_num = num_list.sort(function(a,b){return a-b})[num_list.length-1]
        var num = mymap[max_num]; // 出现的次数 


        num_list.sort(function(a,b){return a-b})[num_list.length-num-1]
        // var person = {
        //     'name':'zhangsan',
        //     'age':18
        // }

        // alert(person['height']) //找不到height  返回undefined 
    </script>
</body>

</html>